package com.wang.utils

import com.alibaba.fastjson.JSON
import com.alibaba.fastjson.JSONObject
import com.alibaba.fastjson.serializer.SerializerFeature

object StringUtils {
    fun firstLowCase(s: String) = s[0].toLowerCase() + s.substring(1)

    fun firstUpperCase(s: String) = s[0].toUpperCase() + s.substring(1)

    fun upperCamelName(s: String) = s.split("_").map(StringUtils::firstUpperCase).reduce { s1, s2 -> s1 + s2 }

    fun fieldName(str: String) = str.split("_").reduceIndexed { index, acc, s ->
        if (index == 0) s else acc + firstUpperCase(s)
    }

    fun printJson(json: Any) {
        println(
            JSON.toJSONString(
                json, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue,
                SerializerFeature.WriteDateUseDateFormat
            )
        )
    }
}